package com.njbdqn.ALi.zjg.Controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.caikun.entity.Userinfos;
import com.njbdqn.ALi.zjg.entity.PageHelper;
import com.njbdqn.ALi.zjg.services.ReplyService;
import com.njbdqn.ALi.zjg.services.SendCommentService;
import com.njbdqn.ALi.zjg.vo.TotalNumberVO;
import com.xubao.ali.services.PrintWriterService;

/**
 * Servlet implementation class ReplysController
 */
public class ReplysController extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private PrintWriterService out = new PrintWriterService();
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		HttpSession session = request.getSession();
		Userinfos user = null;
		user = (Userinfos)session.getAttribute("user");
		
		user.setAccount(user.getAccount());
		
		String page = request.getParameter("page");
		if(page==null){
			page="1";
		}
		int cp = Integer.parseInt(page);
		
		ReplyService rs = new ReplyService();
		
		SendCommentService sc = new SendCommentService();
		
		PageHelper ph = rs.findPage(cp,user.getAccount());
		List<Object> a = ph.getRows();
		TotalNumberVO maxpagination = new TotalNumberVO(ph.getTotal());
		
		a.add(0, maxpagination);
		out.send(response, a);
	}

}
